import {reqCartList,reqAddOrUpdateShopCar} from '@/api'


const state ={
    cartlist:[],
    
};
const mutations  ={
    GETCARTLIST(state,cartlist){
        state.cartlist = cartlist;
    }
};
const actions = {
    //获取购物车的数据
    async getCartList ({commit}){
        let result = await reqCartList();
        console.log(result);
        if(result.code == 200){
            commit('GETCARTLIST',result.data)
        }
    },
    //让购物车的数据+-1
    async addOrUpdateShopCart({commit},{skuId,skuNum}){
          let result = await reqAddOrUpdateShopCar(skuId,skuNum);
          if(result.code ==200){
              return "ok";
          }else{
            return Promise.reject(new Error("faile"));
          }
    },
     //删除购物车某一个产品
  async deleteCartListBySkuId({ commit }, skuId) {

  }
};
const getters = {
    cartlist(state){
           return state.cartlist[0] ||{}
    }
};
export default {
    state,
    mutations,
    actions,
    getters
}
